<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>非父子组件之间数据的传递</title>
	</head>
	<body>
		<div id="dataTran">
			<child content='Paul'></child>
			<child content='Geroge'></child>
		</div>
		
		<script src="js/vue.js"></script>
		<script>
			
			Vue.prototype.bus = new Vue()
			
			Vue.component('child',{
				props:{
					content:String
				},
				template:"<div @click='handleClick'>{{selfContent}}</div>",
				data:function(){
					return{
						selfContent:this.content
					}
				},
				methods:{
					handleClick:function(){
						this.bus.$emit('change',this.selfContent)
					}
				},
				mounted:function(){
					let this_ = this
					this.bus.$on('change',function(msg){
						this_.selfContent = msg
					})
				}
			})
			
			let vm = new Vue({
				el:'#dataTran',
				
			})
		</script>
	</body>
</html>
